package com.qfedu.dao.impl;

import com.qfedu.dao.GoodDao;
import com.qfedu.entity.Good;
import com.qfedu.util.DBUtil;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class GoodDaoImpl implements GoodDao {
    @Override
    public List<Good> findAll() throws SQLException {
        List<Good> goods = new ArrayList<>();
        String sql = "select * from tb_good";
        //注册驱动，得到连接对象
        Connection con = DBUtil.getConn();
        //创建语句对象
        Statement statement = con.createStatement();
        //执行sql语句，得到结果集
        ResultSet rs = statement.executeQuery(sql);
        while(rs.next()){
            String name = rs.getString("good_name") ;
            int pass = rs.getInt("good_cost") ;
            Good good = new Good();
            good.setGoodName(name);
            good.setGoodCost(pass);
            goods.add(good);
        }
        return goods;
    }
}
